<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>砍价规则</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/uploadImg.css">
    <!--日期选择插件-->
    <link rel="stylesheet" href="js/bootstrap-datepicker/bootstrap-datepicker3.min.css">

</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">

                    <div id="toolbar" class="toolbar-btn-action">
                        <form class="form-inline" method="post" id="searchForm">
                            <div class="form-group">
                                <label>规则名称:</label>
                                <input type="text" class="form-control" name="ruleName">
                            </div>
                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round" type="button" id="searchFormBtn">查询</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-success btn_query btn-round" type="button" id="addBtn">添加砍价规则</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-warning btn_query btn-round" type="button" id="editBtn">编辑砍价规则</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-danger btn_query btn-round" type="button" id="deleteBtn">删除砍价规则</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-primary btn_query btn-round" type="button" id="addProductBtn">砍价商品管理</button>
                            </div>
                        </form>
                    </div>

                </div>
                <div class="card-body">
                    <table id="grid_data" class="table text-nowrap"></table>
                </div>
            </div>
        </div>
    </div>

    <!--  添加与编辑模态框 -->
    <div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <span>添加/编辑</span>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <div id="error_tips" style="color: #c9302c"></div>
                </div>
                <div class="modal-body">
                    <form id="addOrEditForm" method="post" enctype="multipart/form-data">
                        <div class="row">

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon" id="basic-account">规则名称</span>
                                    <input type="hidden" name="id">
                                    <input type="text" name="ruleName" class="form-control">
                                    <span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
                                </div>
                            </div>

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon" id="start-time">开始时间</span>
                                    <input type="text" class="form-control js-datepicker" data-date-format="yyyy-mm-dd" name="startTime" id="startTime" autocomplete="off" placeholder="请选择时间">
                                </div>
                            </div>

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon" id="end-time">结束时间</span>
                                    <input type="text" class="form-control js-datepicker" data-date-format="yyyy-mm-dd" name="endTime" id="endTime" autocomplete="off" placeholder="请选择时间">
                                </div>
                            </div>

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon" id="bargainAmount">砍价人数</span>
                                    <input type="number" name="bargainAmount"  class="form-control" onkeyup="this.value=this.value.replace(/[^bai0-9-]+/,'');" value="2" min="2" aria-valuemin="2" aria-valuenow="2">
                                </div>
                            </div>

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon" id="helpCount">帮砍次数</span>
                                    <input type="number" name="helpCount" class="form-control" onkeyup="this.value=this.value.replace(/[^bai0-9-]+/,'');" value="1" min="1" aria-valuemin="1" aria-valuenow="1">
                                </div>
                            </div>

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon" id="bargainCount">砍价次数</span>
                                    <input type="text" name="bargainCount"  class="form-control" onkeyup="this.value=this.value.replace(/[^bai0-9-]+/,'');">
                                </div>
                            </div>

                            <div class="col-xs-12">
                                <div class="input-group m-b-10">
                                    <span class="input-group-addon">广告排序</span>
                                    <input type="text" name="ruleOrder" class="form-control" onkeyup="this.value=this.value.replace(/[^bai0-9-]+/,'');">
                                </div>
                            </div>

                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary addSaveBtn" id="saveBtn">保存</button>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>

    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
    <script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
    <script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
    <!-- bootstrap表单验证插件 -->
    <script type="text/javascript" src="js/bootstrapvalidator/dist/js/bootstrapValidator.js"></script>
    <!-- bootstrap弹出框插件 -->
    <script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
    <!-- 表单填充插件 -->
    <script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>
    <!--表单通用CURD操作-->
    <script type="text/javascript" src="js/zero2one/zero2one.curd.js"></script>
    <!--日期选择插件-->
    <script src="js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script src="js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
    <script type="text/javascript" src="js/main.min.js"></script>

    <script type="text/javascript">


        //设置表头
        var columns = [
            {checkbox: true},
            {field: 'id',title: 'ID'},
            {field: 'ruleName',title: '规则名称'},
            {field: 'startTime',title: '开始时间'},
            {field: 'endTime',title: '结束时间'},
            {field: 'bargainAmount',title: '砍价人数'},
            {field: 'helpCount',title: '帮砍次数'},
            {field: 'bargainCount',title: '砍价次数'},
            {field: 'ruleStatus',title: '规则状态',formatter:function (value,row) {
                    var checked = value == 1 ? "checked" : "";
                    return '<label class="lyear-switch switch-solid switch-success"><input type="checkbox" '+checked+' onclick="status('+value+','+row.id+')"><span></span>'+(value == 1 ? "开启" : "关闭")+'</label>';

                }},
            {field: 'ruleOrder',title: '规则顺序'},
            {field: 'operatorName',title: '操作人名称'},
            {field: 'operatorTime',title: '操作时间',formatter: function (value) {return zero2one.dateFormat(value, 'Y-m-d H:i:s')}},
        ];

        //加载列表信息
        zero2one.table("/remote/bargain/list", columns);


        //查询重新加载
        zero2one.query();

        //点击添加弹出模态框
        zero2one.addModal();


        //点击编辑弹出模态框
        zero2one.editModal();

        // 加载开始时间选择(校验) 
        $("#startTime").on('changeDate change',function(e) {
            $('#addOrEditForm').data('bootstrapValidator')
                .updateStatus('startTime', 'NOT_VALIDATED',null)
                .validateField('startTime');
        });

        // 加载结束时间选择(校验) 
        $("#endTime").on('changeDate change',function(e) {
            $('#addOrEditForm').data('bootstrapValidator')
                .updateStatus('endTime', 'NOT_VALIDATED',null)
                .validateField('endTime');
        });

        //表单校验
        $('#addOrEditForm').bootstrapValidator({
            fields: {
                ruleName: {validators: {notEmpty: {message: '规则名称不能为空'}}},
                startTime: {validators: {notEmpty: {message: '开始时间不能为空'}}},
                endTime: {validators: {notEmpty: {message: '结束时间不能为空'}}}
            }
        });


        //保存按钮
        zero2one.save("/remote/bargain/addOrEdit");

        //点击删除砍价规则
        zero2one.delete("/remote/bargain/deleteByIds");

        //点击开关按钮修改状态
        function status(value,id) {
            zero2one. request("/remote/bargain/status", {"status": value == 1 ? 2 : 1,"id": id},function (data){
                    window.location.reload();
            });
        }







    </script>
</div>
</body>
</html>
